<template>
	<view class="activity">
		<view class="banner_box">
			<swiper :autoplay="true" class="banner">
				<swiper-item class="banner" v-for="(item,i) in topImgList">
					<image class="banner" :src="item.pic" mode="aspectFill"></image>
				</swiper-item>
			</swiper>
			<view class="search-box">
				<view class="">
					<view class="">
						<view class="search_input">
							<image src="../../static/img/search-gray.png" mode=""></image>
							<input type="text" placeholder="关键词搜索" v-model="keywords" @confirm="onSearch()"
								placeholder-class="placeholder_style" />
						</view>
						<view class="search_btn" @click="onSearch()">搜索</view>
					</view>
				</view>
			</view>
		</view>
		<view class="content_box">
			<view class="activity_type">
				<scroll-view scroll-y="true" class="scroll-Y">
					<block v-for="(item,index) in typeList" :key="index">
						<view class="type_item" :class="{'active_type':currentType==index}" @tap="changeType(index)">
							<image src="../../static/img/type_line.png" mode=""></image>
							<view class="type_name">{{item.name}}</view>
						</view>
					</block>
				</scroll-view>
			</view>
			<view class="activity_list">
				<scroll-view scroll-y="true" class="scroll-Y">
					<block v-for="(item,i) in list" :key="i">
						<view class="activity_item" @tap="handleDetail(item.id)">
							<view class="item_t">
								<image class="cover_img" :src="item.image" mode="aspectFill"></image>
								<view class="">
									<view class="activity_name">{{item.storeName}}</view>
									<!-- <view class="activity_time">时间：{{item.activityStartTime}}</view> -->
									<view class="activity_time">{{item.storeInfo}}</view>
									<view class="flex a-c wrap">
										<view class="tag">{{ item.keyword }}</view>
									</view>
									<view class="activity_price">
										<view class="">
											<text>￥</text>
											<text class="pirce_val">{{item.price}}</text>
										</view>
									</view>
								</view>
							</view>
							<view class="address">
								<uni-icons type="location-filled" color="#999999" size="16"></uni-icons>
								<text>{{item.address}}</text>
							</view>
						</view>
					</block>
					<view style="text-align: center;" v-if="list.length==0">
						<image style="width: 200rpx;height: 200rpx;" src="../../static/nodata.png"></image>
						<view style="color: #999;text-align: center;">暂无数据</view>
					</view>
					<view style="text-align: center;color: #999;font-size: 24rpx;" v-if="noMoreData&&list.length!=0">
						没有更多啦
					</view>
				</scroll-view>

			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				topImgList:[],
				keywords: '',
				typeList: [],
				currentType: 0,
				page: 1,
				lastPage: 1,
				noMoreData: false,
				list: [],
			}
		},
		onShow() {
			this.getImg()
			this.getClassyfy()
		},
		watch: {
			keywords(item1, item2) {
				if (item1 == '') {
					setTimeout(() => {
						this.onSearch()
					}, 500)
				}
			}
		},
		onReachBottom() {
			if (this.page < this.lastPage) {
				this.page += 1
				this.getActivities()
			} else {
				this.noMoreData = true
			}
		},
		methods: {
			async getImg() {// 0首页 1研学 2冬夏令营 3红领巾 4托管 5心理测评
				const res = await this.$api.get(`image/get/1`, {});
				if (res.code == 200) {
					// this.topImgList = res.data.image.split(',')
					this.topImgList = res.data.bastBanner
				}
			},
			onSearch() {
				this.page = 1
				this.getActivities()
			},
			async getClassyfy() {// 0=赛事, 1=党建，2=团建，3=研学产品，4=冬夏令营，5=红领巾博物馆 6=托管服务
				const res = await this.$api.get(`team/category/3`, {});
				if (res.code == 200) {
					this.typeList = res.data
					this.getActivities()
				}
			},
			async getActivities() {
				const res = await this.$api.get('competition/week/list', {
					activity: 3,
					categoryId: this.typeList[this.currentType].id,
					page: this.page,
					keywords: this.keywords,
					limit: 10,
					type: 0,
				});
				// console.log(res, "研学")
				if (res.code == 200) {
					const {
						list,
						totalPage
					} = res.data
					if (this.page == 1) {
						this.list = list || [];
						this.lastPage = totalPage || 1;
					} else {
						this.list.push(...list);
					}
					this.page != 1 && list.length == 0 ? this.noMoreData = true : this.noMoreData = false
				}
			},
			changeType(i) {
				this.keywords = ''
				this.currentType = i
				this.page = 1
				this.getActivities()
			},
			handleDetail(id) {
				uni.navigateTo({
					url: '/pages/index/gameDetail/gameDetail?id=' + id
				})
			},
			
		}
	}
</script>

<style lang="scss">
	.activity {
		width: 100%;
		height: 100vh;

		.banner {
			width: 100%;
			height: 400rpx;
		}

		.banner_box {
			width: 100%;
			height: 448rpx;
			position: relative;



			.search-box {
				width: 100%;
				height: 100%;
				position: absolute;
				left: 0;
				top: 0;
				right: 0;
				bottom: 0;
				z-index: 6;
				display: flex;
				align-items: flex-end;

				>view {
					width: 100%;
					height: 102rpx;
					border-radius: 60rpx 60rpx 0 0;
					background-color: #fff;
					display: flex;
					align-items: center;
					padding: 38rpx 26rpx 0;
					box-sizing: border-box;

					>view {
						width: 100%;
						height: 100%;
						border-radius: 30rpx;
						background-color: #F7F7F7;
						display: flex;
						align-items: center;

						.search_input {
							display: flex;
							align-items: center;
							height: 100%;
							flex: 1;
							padding: 0 26rpx;
							box-sizing: border-box;

							image {
								width: 26rpx;
								height: 26rpx;
								margin-right: 12rpx;
							}

							input {
								height: 100%;
								flex: 1;
							}

							.placeholder_style {
								font-size: 26rpx;
								color: #B3B3B3;
							}
						}

						.search_btn {
							width: 106rpx;
							height: 100%;
							display: flex;
							align-items: center;
							justify-content: center;
							border-radius: 30rpx;
							background-color: #2E80FE;
							color: #fff;
							font-size: 26rpx;
						}
					}
				}
			}
		}

		.content_box {
			width: 100%;
			height: calc(100% - 448rpx);
			padding-top: 24rpx;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;

			.scroll-Y {
				height: 100%;
			}

			.activity_type {
				width: 160rpx;
				height: 100%;
				background-color: #F7F7F7;
				overflow: hidden;
				display: flex;
				justify-content: center;

				.type_item {
					width: 100%;
					height: 66rpx;
					font-size: 26rpx;
					display: flex;
					align-items: center;

					image {
						width: 6rpx;
						height: 26rpx;
						opacity: 0;
						margin-right: 22rpx;
					}
				}

				.active_type {
					font-weight: bold;
					background-color: #fff;

					image {
						opacity: 1;
					}
				}
			}

			.activity_list {
				flex: 1;
				height: 100%;

				.activity_item {
					width: 100%;
					padding: 24rpx 26rpx 30rpx 20rpx;
					box-sizing: border-box;

					.item_t {
						display: flex;
						justify-content: space-between;
						padding-bottom: 14rpx;
						border-bottom: 1rpx dashed #F0F0F0;
						margin-bottom: 24rpx;

						.cover_img {
							width: 200rpx;
							height: 160rpx;
							border-radius: 14rpx;
							margin-right: 14rpx;
						}

						>view {
							flex: 1;

							.activity_name {
								width: 320rpx;
								font-size: 30rpx;
								line-height: 30rpx;
								font-weight: bold;
								color: #1A1A1A;
								overflow: hidden;
								white-space: nowrap;
								text-overflow: ellipsis;
							}

							.activity_time {
								font-size: 24rpx;
								line-height: 24rpx;
								color: #999999;
								padding: 14rpx 0;
							}

							.activity_price {
								display: flex;
								justify-content: flex-end;
								font-size: 24rpx;
								font-weight: bold;
								color: #FF0404;

								.pirce_val {
									font-size: 36rpx;
									color: #FF0000;
								}
							}
						}
					}

					.address {
						display: flex;
						align-items: center;
						font-size: 24rpx;
						color: #999999;
						line-height: 24rpx;
					}
				}
			}
		}
	}
</style>